package top.kaoshanji.p2ch06a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.sql.rowset.JdbcRowSet;
import javax.sql.rowset.RowSetFactory;
import javax.sql.rowset.RowSetProvider;
import java.sql.SQLException;

/**
 * 代码清单 p2ch06a-04：使用工厂方法创建RowSet接口的实现对象的示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/17 16:54
 */
public class RowSetExample01 {

    private static final Logger logger = LogManager.getLogger(RowSetExample01.class);

    public static void main(String[] args) throws SQLException {
        logger.info("...代码清单 p2ch06a-04：使用工厂方法创建RowSet接口的实现对象的示例...");

        RowSetFactory rsFactory = RowSetProvider.newFactory();
        try (JdbcRowSet jrs = rsFactory.createJdbcRowSet()){
            jrs.setUrl("jdbc:derby://localhost/p2-java7book");
            jrs.setCommand("SELECT * FROM book");
            jrs.execute();;

            jrs.absolute(1);
            jrs.updateString("name", "New book");
            jrs.updateRow();
        }

    }

}
